#!/usr/bin/env python3

import sys
import os

def do_grep(keys, filename):
    for index, line in enumerate(open(filename)):
        if keys in line:
            line = line.replace(keys, "\033[31m%s\033[0m" % keys)
            print("%5d:%s" % (index + 1, line), end='')

def main(argv):
    if len(argv) < 3:
        print("命令参数传递错误, 必须指定关键词和文件!")
        return

    do_grep(argv[1], argv[2])

if __name__ == "__main__":
    main(sys.argv)
